home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Leser 15
/
Amiga Plus Leser CD 15.iso
/
Tools
/
Development
/
PluginSRC_EvenMore
/
Troff2Text.e
< prev
next >
Wrap
Text File
|
2002-03-12
|
14KB
|
595 lines
/*
Troff2Text
EvenMore FileIO plugin
Author: Chris Perver
Copyright (c) 2001
*/
OPT REG=5
LIBRARY 'troff2text.plugin',1,1,'Troff2Text 1.01' IS em_main, em_end, em_info, em_pluginid, em_begin, em_format
MODULE 'tools/ctype', '*epo'
DEF mem2:PTR TO CHAR, count2 =0
DEF ital = 1,
bold = 2,
italbold = 3,
roman = 4
PROC em_isdatatype(bf, bl)
DEF pos = 0, rs = FALSE, working = TRUE
WHILE working
IF Long(bf + pos) = ".TH "
working := FALSE
rs := TRUE
ENDIF
WHILE bf[pos] <> "\n"
INC pos
ENDWHILE
INC pos
IF pos >= bl THEN working := FALSE
ENDWHILE
ENDPROC rs
PROC setfontstyle(fs)
SELECT fs
CASE bold
mem2[count2++] := "\e"
mem2[count2++] := "["
mem2[count2++] := "1"
mem2[count2++] := "m"
CASE ital
mem2[count2++] := "\e"
mem2[count2++] := "["
mem2[count2++] := "3"
mem2[count2++] := "m"
CASE italbold
mem2[count2++] := "\e"
mem2[count2++] := "["
mem2[count2++] := "1"
mem2[count2++] := ";"
mem2[count2++] := "3"
mem2[count2++] := "m"
CASE roman
mem2[count2++] := "\e"
mem2[count2++] := "["
mem2[count2++] := "0"
mem2[count2++] := "m"
ENDSELECT
ENDPROC
PROC em_parsedata(epo:PTR TO em_pluginobj)
DEF memadr:PTR TO CHAR, lenadr, len2
DEF count = 0
DEF notdone = TRUE
DEF man[256]:STRING, wordwrap = 80, cchar = 0, ww = TRUE, oldpos = 0, i, j
DEF laststyle = 0
DEF style = 0
DEF isbreak = 0
memadr := epo.buffer
lenadr := epo.length
mem2 := epo.nbuffer
len2 := epo.nlength
mem2[len2] := "\n"
WHILE notdone AND (count < lenadr)
SELECT 256 OF memadr[count]
-> FORMATING
CASE $5C
i := count
WHILE memadr[i] <> "\n" DO INC i
INC i
StrCopy(man, memadr + count, 10)
SELECT 256 OF memadr[count+1]
CASE "*"
SELECT 256 OF memadr[count+2]
-> SPECIAL
CASE "("
-> TRADEMARK
IF InStr(man, '*(Tm') = 1
count := count + 3
-> QUOTES
ELSEIF InStr(man, '*(L"') = 1
count := count + 4
ELSEIF InStr(man, '*(R"') = 1
count := count + 4
-> QUOTES
ELSEIF InStr(man, '*(lq') = 1
mem2[count2++] := $22
INC cchar
count := count + 5
ELSEIF InStr(man, '*(rq') = 1
mem2[count2++] := $22
INC cchar
count := count + 5
ELSE
mem2[count2++] := memadr[count++]
INC cchar
ENDIF
-> DEFAULT FONT SIZE
CASE "S"
count := count + 3
-> (R)
CASE "R"
mem2[count2++] := $ae
INC cchar
count := count + 3
DEFAULT
count := count + 3
ENDSELECT
-> NON SPACE CHAR
CASE "&"
count := count + 2
-> COMMENT
CASE $22
count := i
-> SIZE
CASE "s"
SELECT 256 OF memadr[count + 2]
CASE "-"
count := count + 4
DEFAULT
count := count + 3
ENDSELECT
-> STYLE
CASE "f"
SELECT 256 OF memadr[count + 2]
CASE "I"
laststyle := style
style := ital
setfontstyle(style)
count := count + 3
CASE "B"
laststyle := style
style := bold
setfontstyle(style)
count := count + 3
CASE "R"
laststyle := style
style := roman
setfontstyle(style)
count := count + 3
DEFAULT
INC cchar
mem2[count2++] := memadr[count++]
ENDSELECT
DEFAULT
INC cchar
mem2[count2++] := memadr[count++]
ENDSELECT
-> LF
CASE "\n", "\b"
IF isspace(memadr[count-1]) = FALSE THEN mem2[count2++] := " "
INC count
SELECT isbreak
-> Font revert
CASE 2
style := roman ->laststyle
setfontstyle(style)
isbreak := 0
-> Line break
CASE 1
mem2[count2++] := "\n"
isbreak := 0
cchar := 0
ENDSELECT
-> COMMAND
CASE "."
-> GET END OF COMMAND
i := count
WHILE memadr[i] <> "\n" DO INC i
INC i
StrCopy(man, memadr + count, 10)
SELECT 256 OF memadr[count + 1]
CASE "b"
IF InStr(man, '.bp') = 0
mem2[count2++] := "\n"
mem2[count2++] := "\n"
cchar := 0
count := i
-> LINE BREAK
ELSEIF InStr(man, '.br') = 0
mem2[count2++] := "\n"
cchar := 0
count := i
ELSE
mem2[count2++] := memadr[count++]
INC cchar
ENDIF
CASE "B"
IF InStr(man, '.B ') = 0
laststyle := style
style := bold
setfontstyle(bold)
j := count + 1
WHILE memadr[j] = " " DO INC j
IF memadr[j] <> "\n" THEN isbreak := 2
count := count + 3
ELSEIF InStr(man, '.BI ') = 0
laststyle := style
style := italbold
setfontstyle(style)
j := count + 1
WHILE memadr[j] = " " DO INC j
IF memadr[j] <> "\n" THEN isbreak := 2
count := count + 4
ELSEIF InStr(man, '.BR ') = 0
laststyle := style
style := bold
setfontstyle(style)
j := count + 1
WHILE memadr[j] = " " DO INC j
IF memadr[j] <> "\n" THEN isbreak := 2
count := count + 4
-> LINE BREAK
ELSEIF InStr(man, '.BR') = 0
mem2[count2++] := "\n"
cchar := 0
count := i
ELSE
mem2[count2++] := memadr[count++]
INC cchar
ENDIF
-> MACRO
CASE "d"
IF InStr(man, '.de') = 0
WHILE memadr[count] <> "\n"
INC count
EXIT (memadr[count] = "." AND memadr[count+1] = ".")
ENDWHILE
ELSE
mem2[count2++] := memadr[count++]
INC cchar
ENDIF
CASE "D"
-> SET TAB SIZES
IF InStr(man, '.DT') = 0
count := i
ELSE
mem2[count2++] := memadr[count++]
INC cchar
ENDIF
CASE "f"
IF InStr(man, '.ft') = 0
IF memadr[count + 2] = " "
style := laststyle
ELSE
SELECT 256 OF memadr[count+3]
CASE "B"
IF memadr[count+4] <> "I"
laststyle := style
style := bold
setfontstyle(style)
count := i
ELSE
laststyle := style
style := italbold
setfontstyle(style)
count := i
ENDIF
CASE "I"
laststyle := style
style := ital
setfontstyle(style)
count := i
CASE "R"
count := i
DEFAULT
count := i
ENDSELECT
ENDIF
ELSE
mem2[count2++] := memadr[count++]
INC cchar
ENDIF
CASE "I"
IF InStr(man, '.I ') = 0
laststyle := style
style := ital
setfontstyle(style)
j := count + 1
WHILE memadr[j] = " " DO INC j
IF memadr[j] <> "\n" THEN isbreak := 2
count := count + 2
ELSEIF InStr(man, '.IB ') = 0
laststyle := style
style := italbold
setfontstyle(style)
j := count + 1
WHILE memadr[j] = " " DO INC j
IF memadr[j] <> "\n" THEN isbreak := 2
count := count + 3
ELSEIF InStr(man, '.IR ') = 0
laststyle := style
style := ital
setfontstyle(style)
j := count + 1
WHILE memadr[j] = " " DO INC j
IF memadr[j] <> "\n" THEN isbreak := 2
count := count + 3
-> PARA
ELSEIF InStr(man, '.IP') = 0
count := i
mem2[count2++] := "\n"
mem2[count2++] := "\t"
cchar := 1
ELSE
mem2[count2++] := memadr[count++]
INC cchar
ENDIF
CASE "L"
-> LINE BREAK
IF InStr(man, '.LP') = 0
mem2[count2++] := "\n"
mem2[count2++] := "\n"
cchar := 0
count := i
ELSE
mem2[count2++] := memadr[count++]
INC cchar
ENDIF
CASE "P"
-> PARA
IF InStr(man, '.PP') = 0
mem2[count2++] := "\n"
mem2[count2++] := "\n"
cchar := 0
count := i
ELSEIF InStr(man, '.P') = 0
mem2[count2++] := "\n"
mem2[count2++] := "\n"
cchar := 0
count := i
ELSE
mem2[count2++] := memadr[count++]
INC cchar
ENDIF
CASE "R"
-> RESET MARGINS
IF InStr(man, '.RE') = 0
count := i
-> RESET MARGINS
ELSEIF InStr(man, '.RS') = 0
count := i
ELSE
mem2[count2++] := memadr[count++]
INC cchar
ENDIF
CASE "s"
-> LINE BREAK
IF InStr(man, '.sp') = 0
mem2[count2++] := "\n"
mem2[count2++] := "\n"
cchar := 0
count := i
ELSE
mem2[count2++] := memadr[count++]
INC cchar
ENDIF
CASE "S"
-> HEADER
IF InStr(man, '.SH ') = 0
mem2[count2++] := "\n"
cchar := 0
mem2[count2++] := "\e"
mem2[count2++] := "["
mem2[count2++] := "4"
mem2[count2++] := "3"
mem2[count2++] := "m"
isbreak := 1
count := count + 4
ELSEIF InStr(man, '.SS ') = 0
mem2[count2++] := "\n"
cchar := 0
mem2[count2++] := "\e"
mem2[count2++] := "["
mem2[count2++] := "2"
mem2[count2++] := "m"
isbreak := 1
count := count + 4
ELSEIF InStr(man, '.SM ') = 0
mem2[count2++] := "\n"
cchar := 0
mem2[count2++] := "\e"
mem2[count2++] := "["
mem2[count2++] := "2"
mem2[count2++] := "m"
isbreak := 1
count := count + 4
ELSE
mem2[count2++] := memadr[count++]
INC cchar
ENDIF
CASE "T"
-> PARA
IF InStr(man, '.TP') = 0
mem2[count2++] := "\n"
cchar := 1
count := i
-> UNKNOWN
ELSEIF InStr(man, '.TQ') = 0
mem2[count2++] := "\n"
cchar := 1
count := i
isbreak := 1
ELSE
mem2[count2++] := memadr[count++]
INC cchar
ENDIF
DEFAULT
mem2[count2++] := memadr[count++]
INC cchar
ENDSELECT
DEFAULT
mem2[count2++] := memadr[count++]
INC cchar
-> WORDWRAP IF NECESSARY
IF ww = TRUE
IF cchar >= wordwrap
-> Find last space
IF isspace(mem2[count2]) = TRUE
mem2[count2++] := "\n"
cchar := 0
ELSE
oldpos := count2
WHILE isspace(mem2[oldpos]) = FALSE
mem2[oldpos+1] := mem2[oldpos]
DEC oldpos
-> mem2[oldpos+1] := mem2[oldpos]
ENDWHILE
-> DEC oldpos
-> CopyMem(mem2 + oldpos, mem2 + oldpos + 1, count2 - oldpos)
mem2[oldpos] := "\n"
cchar := count2 - oldpos
-> INC count2
ENDIF
ENDIF
ENDIF
ENDSELECT
ENDWHILE
ENDPROC mem2, count2
-><
-> *** STANDARD PROCS FOR PLUGINS
PROC em_begin(epo:PTR TO em_pluginobj)
DEF m2, l2
IF em_isdatatype(epo.buffer, epo.length)
RETURN "MEM", (epo.length * 2)
ELSE
RETURN FALSE
ENDIF
ENDPROC
PROC em_main(epo:PTR TO em_pluginobj)
DEF m2, l2
m2, l2 := em_parsedata(epo)
epo.nlength := l2
RETURN TRUE
ENDPROC
PROC em_end() IS EMPTY
PROC em_info() IS 'Troff2Text 1.03'
PROC em_pluginid() IS "FILE"
PROC em_format() IS 'Troff'
PROC main() IS EMPTY